new Vue({
	el: '#app',
	data: {
		uid: '',
		api_token: '',
		url: '',
		avatar: '',
		avatar_path: '',
		user: '',
		path: '',
		nickname: ''
	},
	mounted: function() {
		this.init();
	},
	methods: {
		init: function() {
			var self = this;
			self.uid = $api.getStorage('uid');
			self.api_token = $api.getStorage('api_token');
			self.url = $api.getStorage('url');
			self.avatar = $api.getStorage('avatar');
			self.avatar_path = $api.getStorage('avatar_path');
			self.nickname = $api.getStorage('nickname');
			if(self.uid) {
				self.getUserMsg();
			} else {
				apiready = function() {
					self.layout();
				};
			}
		},
		getUserMsg: function() {
			var self = this;
			apiready = function() {
				self.getMsg();
			};
		},
		close: function() {
			api.closeWin()
		},
		//登出
		layout: function() {
			api.openWin({
				name: 'login',
				url: '../../html/login/login.html',
				reload: true,
				vScrollBarEnabled: false,
				pageParam: {
					index: 4
				}
			});
		},
		//读取用户信息
		getMsg: function() {
			var self = this;
			console.log(self.uid);
			var data = {
				uid: self.uid,
				token: self.api_token
			};
			$.post(base + config.user_show, data, function(msg) {
				console.log(msg);
				if(msg.error == 0) {
					self.user = msg.data;
					self.nickname = msg.data.nickname;
					if(self.user.integral == null) {
						self.user.integral = 0;
					} else {

					}
					self.path = msg.url;
				} else {
					console.log(msg.error_msg);
					api.toast({
						msg: msg.error_msg,
						duration: 2000,
						location: 'middle'
					});
				}
			}, 'json');
		},
		//跳转到用户基本设置页面
		jumpSet: function() {
			api.openWin({
				name: 'user-setting',
				url: 'userSetting.html',
				//				reload: true
				vScrollBarEnabled: false,
			});
		},
		//跳转到我的订单页面
		jumpOrder: function() {
			api.openWin({
				name: "my-order",
				url: "myOrder.html",
				//				reload: true
				vScrollBarEnabled: false,
			});
		},
		//跳转到我的钱包页面
		jumpWallet: function() {
			api.openWin({
				name: "my-wallet",
				url: "myWallet.html",
				//				reload: true
				vScrollBarEnabled: false,
			});
		},
		//跳转到我的优惠券页面
		jumpDiscount: function() {
			api.openWin({
				name: 'myCoupon',
				url: 'myCoupon.html',
				//				reload: true
				vScrollBarEnabled: false,
			});
		},
		//跳转到我的推荐页面
		jumpRecommendation: function() {
			api.openWin({
				name: "my-recommendation",
				url: "myRecommendation.html",
				//				reload: true
				vScrollBarEnabled: false,
			});
		},
		//跳转到我的信息页面
		jumpMessage: function() {
			api.openWin({
				name: "my-message",
				url: "myMessage.html",
				//				reload: true
				vScrollBarEnabled: false,
			});
		}
	}
})